/**
 * 
 */
package org.ejc.tech.combo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.log4j.Category;
import org.ejc.api.registration.RegistrantTypeAPIUtil;
import org.ejc.persist.model.RegistrantType;

/**
 * @author Brian Boyle
 *
 */
public class RegistrantTypeHandlerImpl implements IComboHandler {

	
static HashMap map=new HashMap();
private static final String PREFIX = "org.ejc.type.registranttype.";
	Category log = Category.getInstance(RegistrantTypeHandlerImpl.class);

	public Collection getLocalizedCollection(Locale locale) {
		return (Collection) map.get(locale.getLanguage());
	}

	public void setupHandler(Collection locales) {
		for (Iterator iter = locales.iterator(); iter.hasNext();) {
				Collection<RegistrantType> regTypeCol = new ArrayList<RegistrantType>();
				Locale locale = (Locale) iter.next();
				ResourceBundle resource = ResourceBundle.getBundle(
						"org.ejc.resources.RegistrantType", locale);
				try {
					Collection c = RegistrantTypeAPIUtil.getLocalHome().create().getRegistrantTypes();

					for (Iterator iter1 = c.iterator(); iter1.hasNext();) {
						RegistrantType element = (RegistrantType) iter1.next();
						String key = PREFIX + element.getRegistrantTypeDesc();
						String localizedName = (String) resource.getObject(key);


						RegistrantType regType = new RegistrantType();
						regType.setRegistrantTypeId(element.getRegistrantTypeId());
						regType.setRegistrantTypeDesc(localizedName);
						regTypeCol.add(regType);
					}
				} catch (Exception e) {
					log.fatal("Error in setting up country codes!", e);
				}
				map.put(locale.getLanguage(), regTypeCol);
			}
		}
		
		
}
